package com.example.mall.web.controller;

import com.example.mall.domain.LogisticsStatusHistory;
import com.example.mall.dto.LogisticsStatusHistoryDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.LogisticsStatusHistoryQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ILogisticsStatusHistoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logisticsStatusHistory")
public class LogisticsStatusHistoryController {

    @Autowired
    public ILogisticsStatusHistoryService logisticsStatusHistoryService;

    /**
     * 分页查询物流状态历史表信息
     * @param logisticsStatusHistoryQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询物流状态历史表信息",notes = "分页查询物流状态历史表信息",httpMethod = "GET")
    public JSONResult queryPage(LogisticsStatusHistoryQuery logisticsStatusHistoryQuery){
        PageDTO<LogisticsStatusHistoryDto> logisticsStatusHistoryDtoPageDTO = logisticsStatusHistoryService.queryPage(logisticsStatusHistoryQuery);
        return JSONResult.success("查询成功",logisticsStatusHistoryDtoPageDTO);
    }

    /**
     * 根据id查询物流状态历史表信息
     * @param historyId
     * @return
     */
    @GetMapping("query/{historyId}")
    @ApiOperation(value = "根据id查询物流状态历史表信息",notes = "根据id查询物流状态历史表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("historyId")Long historyId){
        //1.根据id查询用户信息
        if (historyId == null){
            throw new GlobalCustomerException(ErrorEnumCode.HISTORYID_NOT_ID);
        }
        LogisticsStatusHistory logisticsStatusHistory = logisticsStatusHistoryService.getById(historyId);
        return JSONResult.success("查询成功",logisticsStatusHistory);
    }

    /**
     * 根据id查询物流状态历史表信息
     * @param historyId
     * @return
     */
    @GetMapping("queryLogisticsStatusHistoryById/{historyId}")
    @ApiOperation(value = "根据id查询物流状态历史表信息",notes = "根据id查询物流状态历史表信息",httpMethod = "GET")
    public JSONResult queryLogisticsStatusHistoryById(@PathVariable("historyId")Long historyId){
        //1.根据id查询用户信息
        if (historyId == null){
            throw new GlobalCustomerException(ErrorEnumCode.HISTORYID_NOT_ID);
        }
        LogisticsStatusHistory logisticsStatusHistory = logisticsStatusHistoryService.queryLogisticsStatusHistoryById(historyId);
        return JSONResult.success("查询成功",logisticsStatusHistory);
    }

    /**
     * 查询全部物流状态历史表信息
     * @param
     * @return
     */
    @GetMapping("queryLogisticsStatusHistoryList")
    @ApiOperation(value = "查询全部物流状态历史表信息",notes = "查询全部物流状态历史表信息",httpMethod = "GET")
    public JSONResult queryLogisticsStatusHistoryList(){
        List<LogisticsStatusHistory> logins = logisticsStatusHistoryService.queryLogisticsStatusHistoryList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增物流状态历史表
     * @param logisticsStatusHistoryDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增物流状态历史表",notes = "新增物流状态历史表",httpMethod = "POST")
    public JSONResult insert(@RequestBody LogisticsStatusHistoryDto logisticsStatusHistoryDto){
        logisticsStatusHistoryService.insert(logisticsStatusHistoryDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改物流状态历史表信息
     * @param logisticsStatusHistoryDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改物流状态历史表信息",notes = "修改物流状态历史表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody LogisticsStatusHistoryDto logisticsStatusHistoryDto){
        logisticsStatusHistoryService.update(logisticsStatusHistoryDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除物流状态历史表信息
     * @param historyId
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除物流状态历史表信息",notes = "删除物流状态历史表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("historyId") Long historyId) {
        logisticsStatusHistoryService.delete(historyId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除物流状态历史表信息
     * @param historyIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除物流状态历史表信息",notes = "批量删除物流状态历史表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> historyIds) {
        logisticsStatusHistoryService.deleteBatch(historyIds);
        return JSONResult.success("批量删除成功");
    }
}
